# -*- coding: utf-8 -*-
# Author: jurrabi <jurrabi@gmail.com>
# URL: http://code.google.com/p/mytvalacarta//
#
# This file is part of myTValacarta.
#
# myTValacarta is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# myTValacarta is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with myTValacarta.  If not, see <http://www.gnu.org/licenses/>.
from distutils import errors
'''
Created on 21/08/2010

@author: jurrabi
'''

import sys #Access command line parameters

from tools import logger
logger.debug("[mytvalacarta]Init")


def Start():
    logger.debug("[mytvalacarta]Start()")

    #Input Parameters processing.
    logger.debug("[mytvalacarta]Start: sys.argv= %s" % str(sys.argv))
    params = dict()
    if len(sys.argv) >= 2 and len(sys.argv[2]) > 0:
        params = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))
    logger.debug("[mytvalacarta]Main: params= %s" % str(params))
    
    #Read next action based on action parameter
    if (params.has_key("action")):
        action = params.get("action")
    else:
        action = "MainView"

    #Execute next action
    if action == "MainView":
        import views.main as newview
    else:
        raise RuntimeError("No action to perform") #
    newview.Start(params)
    